package messages;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;

import net.GameNetMessages;

import org.w3c.dom.Document;
import org.w3c.dom.Element;

import logic.Team;

public class UmountObelisk implements GameMessage {
	private int x1;
	private int y1;
	private int x2;
	private int y2;
	private String msg;
	private Team playercolor;
	
	private DocumentBuilder db;
	
	public UmountObelisk(int x1, int y1, int x2, int y2, Team player){
		try {
			db = DocumentBuilderFactory.newInstance().newDocumentBuilder();
		} catch (ParserConfigurationException e) {
			e.printStackTrace();
		}
		this.x1 = x1;
		this.y1 = y1;
		this.x2 = x2;
		this.y2 = y2;
		this.playercolor = player;
		setMessage("Player "+playercolor+" umounts obelisk "+x1+","+y1+"->"+x2+","+y2);
	}
	
	public Team getPlayerTeam(){
		return playercolor;
	}
	
	public int getX1(){
		return x1;
	}
	
	public int getY1(){
		return y1;
	}
	
	public int getX2(){
		return x2;
	}
	
	public int getY2(){
		return y2;
	}

	@Override
	public String getMessage() {
		// TODO Auto-generated method stub
		return msg;
	}

	@Override
	public void setMessage(String message) {
		// TODO Auto-generated method stub

	}
	
	public Document getXMLMessage(){
		Document msg = db.newDocument();
		Element moveMsg = msg.createElement(GameNetMessages.khetMsg);
		msg.appendChild(moveMsg);
		moveMsg.setAttribute("type", GameNetMessages.umountObelisk);
		moveMsg.setAttribute("x1", x1+"");
		moveMsg.setAttribute("y1", y1+"");
		moveMsg.setAttribute("x2", x2+"");
		moveMsg.setAttribute("y2", y2+"");
		return msg;
	}

}
